package device_dao

import (
	"data_monitor/pkg/device/device_model"
	"gorm.io/gorm"
)

func GetDevice(db *gorm.DB, id int64) (device *device_model.Device, err error) {
	query := db.Model(&device_model.Device{})

	err = query.Where("id = ? and is_deleted = 0", id).Find(&device).Error
	if err != nil{
		return nil, err
	}

	return device, nil
}

func GetDeviceList(db *gorm.DB) (devices []device_model.Device, err error) {
	query := db.Model(&device_model.Device{})

	err = query.Where("is_deleted = 0").Find(&devices).Error
	if err != nil{
		return nil, err
	}

	return devices, nil
}